<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var removeElements = function (head, val) {
      if (head === null) {//递归终止 遍历完了链表
        return head;
      }
      head.next = removeElements(head.next, val);//递归调用函数removeElements
      return head.val === val ? head.next : head;//如果当前元素值是val，则返回下一个元素，否则直接返回当前元素
    };
    console.log(removeElements(head = [1, 2, 6, 3, 4, 5, 6], val = 6))
  </script>
</body>

</html>